<!--工作经历表单-->
<template>
  <div class="form">
    <yd-cell-group>
      <yd-cell-item>
        <span slot="left" class="label required">培训起始日期</span>
        <xf-date-picker
          :valid="[{required: true, msg: '请选择培训起始日期'}]"
          v-model="form.aae030"
          ref="aae030"
          placeholder="请选择培训起始日期"
          :endDate="new Date()"
          slot="right"></xf-date-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">培训终止日期</span>
        <xf-date-picker
          :valid="[{required: true, msg: '请选择培训终止日期'}]"
          v-model="form.aae031"
          ref="aae031"
          placeholder="请选择培训终止日期"
          slot="right"></xf-date-picker>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">培训机构名称</span>
        <xf-input
          slot="right"
          :valid="[{required: true, msg: '请输入培训机构名称'}]"
          v-model="form.acc0b1"
          ref="acc0b1"
          placeholder="请输入培训班名称"></xf-input>
      </yd-cell-item>
      <yd-cell-item>
        <span slot="left" class="label required">培训主办单位</span>
        <xf-input
          slot="right"
          :valid="[{required: true, msg: '请输入培训主办单位名称'}]"
          v-model="form.aaab01"
          ref="aaab01"
          placeholder="请输入培训主办单位名称"></xf-input>
      </yd-cell-item>
    </yd-cell-group>
    <div class="right-bottom">
      <mt-button type="default" size="small" @click="cancel">取消</mt-button>
      <mt-button type="primary" size="small" @click="onSubmit">保存</mt-button>
    </div>
  </div>
</template>
<script>
  import XfDatePicker from '../../../components/xf-date-picker/xf-date-picker.vue'
  import XfInput from '../../../components/xf-input/xf-input.vue'
  import XfPicker from '../../../components/xf-picker/xf-picker.vue'
  import {validate, echo} from '../../../common/js/util'
  import {mapGetters} from 'vuex'

  export default {
    components: {
      XfPicker,
      XfInput,
      XfDatePicker},
    name: 'form-train',
    props: {
      detail: {type: null, default: () => { return {} }}
    },
    computed: {
      ...mapGetters([
        'userInfo'
      ])
    },
    data() {
      return {
        form: {
          personId: this.$route.query.id,
          acc0b0: '',
          aae030: '', // 开始时间
          aae031: '', // 结束时间
          acc0b1: '', // 培训机构名称
          aaab01: '' // 培训主办单位
        }
      }
    },
    methods: {
      cancel() {
        this.$emit('cancel')
      },
      onSubmit() {
        const form = Object.assign({}, this.form)
        validate.call(this, this.form).then(() => {
          this.$post('/admin/person/sapi/personal/records/perEntry/update/train', form, loading => {
            this.$message.loading(loading)
          }).then(res => {
            this.$emit('save')
          })
        })
      }
    },
    created() {
      echo(this.form, this.detail)
    }
  }
</script>
